package test;

import java.lang.reflect.Array;
import java.util.*;

public class test {

	public LinkedList<LinkedList<Integer>> getSubSetList(
			LinkedList<Integer> list) {
		LinkedList<LinkedList<Integer>> result = new LinkedList<LinkedList<Integer>>();

		if (list.isEmpty()) {
			result.add(new LinkedList<Integer>());
			return result;
		}

		Integer head = list.remove(0);

		for (LinkedList<Integer> subSet : getSubSetList(list)) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			tmp.add(head);
			tmp.addAll(subSet);
			result.add(tmp);
			result.add(subSet);
		}

		return result;
	}

	public LinkedList<Integer> unionTwoSet(LinkedList<Integer> set1,
			LinkedList<Integer> set2) {
		if (set1 == null && set2 == null) {
			return null;
		}
		if (set1 != null && set2 == null) {
			return set1;
		}
		if (set2 != null && set1 == null) {
			return set2;
		}
		set1.addAll(set2);
		return set1;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		test t = new test();

		LinkedList<Integer> list = new LinkedList<Integer>();
		list.add(1);
		list.add(2);
		list.add(3);
		// list.add(4);
		LinkedList<Integer> list1 = new LinkedList<Integer>();
		list1.add(4);

		LinkedList<LinkedList<Integer>> result = t.getSubSetList(list);
		result.removeLast();
		System.out.println("size: " + result.size());
		for (LinkedList<Integer> set : result) {
			for (Integer item : set) {
				System.out.print(item);
			}
			System.out.println();
		}

		LinkedList<Integer> tmp = t.unionTwoSet(list, list1);
		if (tmp != null) {
			for (Integer item : tmp) {
				System.out.print("pt: "+item);
			}
		}
		LinkedList<LinkedList<Integer>> h = new LinkedList<LinkedList<Integer>>();
		h.add(new LinkedList<Integer>());
		System.out.println(h.size());
	}

}
